﻿using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Mgrs;
using UnityEngine;

public class PlayerJump : PlayerBaseState {
	public PlayerJump(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => _controller.Jump || _controller.Velocity.y > 0);

		AddNewTransition(PlayerStateEnum.Jump, () => _controller.Jump && !_controller.DownInput && CanJump());
		AddNewTransition(PlayerStateEnum.Fall, () => _controller.Velocity.y <= 0);
	}

	public override void Enter() {
		if (_controller.Jump) {
			AudioManager.Play(_controller.StateAudio, AudioStr.PlayerJumpAudio);
			_controller.Velocity = new UnityEngine.Vector2(0, _controller.ConfigData.JumpSpeed);
			_controller.StateData.CurJumpCnt++;
		}
		_controller.ChangeDir();//登墙之后会用到
		_controller.PlayAnim(PlayerStateEnum.Jump);
		_controller.ResetGravity();
		//Debug.Log(_controller.Velocity);
		//Debug.Log("JumpEnter");
	}


	public override void Exit() {

	}
	bool CanJump() => _controller.StateData.CurJumpCnt < _controller.ConfigData.MaxJumpCnt;

}